package com.cqgc.service.impl;

import com.cqgc.mapper.RoleMapper;
import com.cqgc.pojo.dto.RoleDTO.RoleAddDTO;
import com.cqgc.pojo.dto.RoleDTO.RoleUpdateDTO;
import com.cqgc.pojo.dto.RoleDTO.RoleParm;
import com.cqgc.pojo.entity.PageResult;
import com.cqgc.pojo.entity.Role;
import com.cqgc.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public PageResult list(RoleParm roleParm) {
        PageHelper.startPage(roleParm.getCurrentPage(),roleParm.getPageSize());
        List<Role> roles = roleMapper.pageQuery(roleParm);
        PageInfo<Role> pageInfo = new PageInfo<>(roles);
        int total = (int) pageInfo.getTotal();
        List<Role> list = pageInfo.getList();
        return new PageResult(total,list);
    }

    @Override
    public boolean removeById(int rid) {
        int i = roleMapper.removeById(rid);
        if (i > 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean addRole(RoleAddDTO roleDTO) {
        int i = roleMapper.addRole(roleDTO);
        if (i > 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateRole(RoleUpdateDTO role) {
        int i = roleMapper.updateRole(role);
        if (i > 0){
            return true;
        }
        return false;
    }

    @Override
    public List<Role> list() {
        List<Role> roleList = roleMapper.getRoleInfo();
        return roleList;
    }

    @Override
    public Role getOneAdd(RoleAddDTO roleDTO) {
        Role oneAdd = roleMapper.getOneAdd(roleDTO);
        return oneAdd;
    }

    @Override
    public Role getOneUpdate(RoleUpdateDTO roleDTO) {
        Role oneUpdate = roleMapper.getOneUpdate(roleDTO);
        return oneUpdate;
    }


}
